import { TweenPlugin } from "./TweenPlugin";
import { TweenLite } from "../TweenLite";
//class DynamicPropsPlugin
    
    export  class DynamicPropsPlugin extends TweenPlugin
    {
        constructor()
        {
            
            this.propName = "dynamicProps";
            this.overwriteProps = [];
            this._props = [];
            return;
        }

        public /* override */ onInitTween(arg1: Object, arg2, arg3: TweenLite): Boolean
        {
            var loc2=null;
            this._target = arg3.target;
            var loc1=arg2.params || {};
            this._lastFactor = 0;
            var loc3=0;
            var loc4=arg2;
            for (loc2 in loc4) 
            {
                if (loc2 == "params") 
                {
                    continue;
                }
                this._props[this._props.length] = new DynamicProperty(loc2, arg2[loc2] as Function, loc1[loc2]);
                this.overwriteProps[this.overwriteProps.length] = loc2;
            }
            return true;
        }

        public /* override */ killProps(arg1: Object): void
        {
            var loc1=this._props.length;
            while (loc1--) 
            {
                if (!(this._props[loc1].name in arg1)) 
                {
                    continue;
                }
                this._props.splice(loc1, 1);
            }
            super.killProps(arg1);
            return;
        }

        public /* override */ set changeFactor(arg1: number)
        {
            var loc1=0;
            var loc2=null;
            var loc3=NaN;
            var loc4=NaN;
            if (arg1 != this._lastFactor) 
            {
                loc1 = this._props.length;
                loc4 = arg1 == 1 || this._lastFactor == 1 ? 0 : 1 - (arg1 - this._lastFactor) / (1 - this._lastFactor);
                while (loc1--) 
                {
                    loc2 = this._props[loc1];
                    loc3 = loc2.params ? loc2.getter.apply(null, loc2.params) : loc2.getter();
                    this._target[loc2.name] = loc3 - (loc3 - this._target[loc2.name]) * loc4;
                }
                this._lastFactor = arg1;
            }
            return;
        }

        public static /* const */API: number=1;

        protected /* var */_target: Object;

        protected /* var */_props: Array<any>;

        protected /* var */_lastFactor: number;
    }
}


class DynamicProperty
{
    public DynamicProperty(arg1: string, arg2: Function, arg3: Array<any>)
    {
        super();
        this.name = arg1;
        this.getter = arg2;
        this.params = arg3;
        return;
    }

    public /* var */name: string;

    public /* var */getter: Function;

    public /* var */params: Array<any>;
